/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package foalvleditor.gameobjects;

import java.awt.Point;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JOptionPane;

/**
 *
 * @author fish
 */

public abstract class AbstractGameObject implements Cloneable {

	private int height;
        private int width;
        private int layer;
        private Point position;
        private Bitmap bitmap;
        private String name="GameObjectAdapter";
        private static org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(foalvleditor.core.FoaLvlEditorApp.class).getContext().getResourceMap(Bitmap.class);

        public enum ObjectType{BITMAPOBJECT, BACKGROUND};
        private ObjectType type;

        public AbstractGameObject(Point position, Bitmap bitmap, int layer) {
            try{
                this.bitmap = bitmap.clone();
            }
            catch (CloneNotSupportedException e){
                this.bitmap=bitmap;
            }
                this.height = bitmap.getHeight();
                this.width = bitmap.getWidth();
                this.layer = layer;
                this.position = new Point(position);
                this.setType(ObjectType.BITMAPOBJECT);
        }

    @Override
        public AbstractGameObject clone() throws CloneNotSupportedException {
            return (AbstractGameObject) super.clone();
        }

        public void setLayer(int newlayer){
            this.layer=newlayer;
        }

        public int getLayer(){
            return this.layer;
        }

        public String getName()
        {
            return this.name;
        }

        public void setName(String name)
        {
            this.name=name;
        }

        public ObjectType getType(){
            return this.type;
        }

        public void setType(ObjectType type)
        {
            this.type=type;
        }

	public void setPosition(Point position){
		this.position = new Point(position);
	}

        public void setBitmap(String filename){
            bitmap.setBitmapCode(filename);
            try{
            bitmap=bitmap.clone();
            }
            catch(CloneNotSupportedException e){}
            this.height=bitmap.getHeight();
            this.width=bitmap.getWidth();
        }

        public Bitmap getBitmap() {
            try{
            return bitmap.clone();
            }
            catch (CloneNotSupportedException e){
                return bitmap;
            }
	}

      public ArrayList<Bitmap> getBitmapFamily() {
          ArrayList<Bitmap> bitmapFamily=new ArrayList<Bitmap>();
          if (this.bitmap!=null){
            String objects=resourceMap.getString("@"+this.name.toLowerCase());
            Scanner scanner=new Scanner(objects);
            try{
                Bitmap newMember;
                while (scanner.hasNext())
                {
                    newMember = new Bitmap(scanner.next());
                    bitmapFamily.add(newMember);
                }
            }
            catch (Exception e){
                JOptionPane.showMessageDialog(null, "Error while processing images.");
            }
          }
          return bitmapFamily;
        }

	public int getHeight() {
		return height;
	}

	public Point getPosition() {
		return new Point(position.x,position.y);
	}

	public int getWidth() {
		return width;
	}
}

 class Door extends AbstractGameObject {
    public Door(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Door");
    }
 }

  class Enemy extends AbstractGameObject {
    public Enemy(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
        // public enemy =)))
         this.setName("Enemy");
    }
 }
  
   class Gravitable extends AbstractGameObject {
    public Gravitable(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Gravitable");
    }
 }
   
   class Key extends AbstractGameObject {
    public Key(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Key");
    }
 }

   class Lever extends AbstractGameObject {
    public Lever(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Lever");
    }
 }

   class PlayerObject extends AbstractGameObject {
    public PlayerObject(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Player");
    }
 }

   class Push extends AbstractGameObject {
    public Push(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Player");
    }
 }

      class ReverseGravitable extends AbstractGameObject {
    public ReverseGravitable(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("ReverseGravitable");
    }
 }

      class Scenery extends AbstractGameObject {
    public Scenery(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Scenery");
         this.setType(ObjectType.BACKGROUND);
    }
 }

      class Spike extends AbstractGameObject {
    public Spike(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Spike");
    }
 }

   class StationaryObstacle extends AbstractGameObject {
    public StationaryObstacle(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Stationary");
    }
 }

   class TiltableObject extends AbstractGameObject {
    public TiltableObject(Point position, Bitmap bitmap, int layer){
        super(position, bitmap, layer);
         this.setName("Tiltable");
    }
 }


